/*
05-树7 堆中的路径
*/

#include <stdio.h>
#include <stdlib.h>

/* Heap =========================================*/
#ifndef HeapElementType
#define HeapElementType int
#endif

typedef struct Heap Heap;
struct Heap {
    HeapElementType* data; // 存储元素的数组
    int size; // 元素个数
    int capacity; // 最大容量
    // 堆元素比较器
    int (*compare)(HeapElementType e1, HeapElementType e2);
};

Heap* createHeap(int capacity, int (*compare)(HeapElementType e1, HeapElementType e2)) {
    Heap* h = calloc(1, sizeof(Heap));
    h->data = calloc((capacity+1), sizeof(HeapElementType));
    h->size = 0;
    h->capacity = capacity;
    // h->data[0] = -32767; // 本来应该定义“哨兵”，但因使用比较器，“哨兵”不好确定
    h->compare = compare;
    return h;
}

void freeHeap(Heap* h) {
    free(h->data);
    free(h);
}

int isFullHeap(Heap* h) {
    return h->size+1 > h->capacity;
}

int isEmptyHeap(Heap* h) {
    return h->size < 1;
}

void insertHeap(Heap* h, HeapElementType item) {
    if (isFullHeap(h)) {
        printf("Heap Full");
        return;
    }
    int i = ++h->size;
    // 调整:比较item，与item的父节点（下标：i/2），若大于父节点，把父节点往下移动
    for (; i/2>0 && h->compare(item, h->data[i/2]) > 0; i/=2) {
        h->data[i] = h->data[i/2];
    }
    h->data[i] = item;
}

/* current =======================================*/
// 要小顶堆，
int compare(HeapElementType e1, HeapElementType e2) {
    return e2 - e1;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    Heap* heap = createHeap(n, compare);
    for (int i=0; i<n; i++) {
        int item;
        scanf("%d", &item);
        insertHeap(heap, item);
    }
    for (int i=0; i<m; i++) {
        int pb;
        int idx;
        scanf("%d", &idx);
        for (pb=0; idx>=1; idx/=2) {
            if (pb) {
                printf(" ");
            }
            printf("%d", heap->data[idx]);
            pb = 1;
        }
        printf("\n");
    }
    freeHeap(heap);
}
